Fix issues 2139, 2217 handling Auto delimiter in fromDecimal function#2650
Closed
alleria173 wants to merge 2 commits into
Closed
Fix issues 2139, 2217 handling Auto delimiter in fromDecimal function#2650alleria173 wants to merge 2 commits into
alleria173 wants to merge 2 commits into
Conversation
… used in HMAC recipe
alleria173
marked this pull request as ready for review
July 7, 2026 13:44
Contributor
Author
|
Hi there. Let me know if you need any more commentary/tests to support this pull request. |
Contributor
|
Thanks for your contribution. These issues have now been resolved by the merge of #2270. The HMAC tests would still be useful though - would you care to submit these as a separate stand-alone PR? |
Contributor
Author
|
@GCHQDeveloper581 No problem, I've put the HMAC tests into their own PR #2680 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
fromDecimalinsrc/core/lib/Decimal.mjshas always accepteddelim="Auto"as its default, but never implemented it. It passed"Auto"directly toUtils.charRep(), which has no entry for that string and returnsundefined. Callingstr.split(undefined)in JavaScript returns the whole string as a single-element array, so the input was never actually split into individual values.This caused
Utils.convertToByteStringandUtils.convertToByteArray(called withtype="decimal") to misparse their input. The most visible symptom was that the HMAC operation produced different results for a Latin1 key ofAAvs a Decimal key of65 65, even though both represent the same two bytes.The fix adds an explicit
"Auto"branch that splits on the regex/[^\d-]+/— any run of characters that are not digits or minus signs — and filters out empty strings. This mirrors the approach already used byfromHex, which has its own"Auto"regex branch (/[^a-f\d]|0x/gi). Explicit named delimiters continue to go throughUtils.charRepas before.Existing Issue
Fixes #2139 and fixes #2217.
Screenshots
N/A — no visual changes.
AI disclosure
GitHub Copilot (Claude Sonnet 4.6) was used to assist in diagnosing the root cause and drafting the fix. The code has been reviewed and verified manually.
Test Coverage
Three HMAC regression tests added to
tests/operations/tests/Hash.mjs:HMAC: Decimal key space-delimited matches Latin1 key— verifies"65 65"(the previously broken case) produces the correct digestHMAC: Latin1 key matches space-delimited Decimal key— the known-good Latin1 baseline ("AA") producing the same digestHMAC: Decimal key comma-delimited matches Latin1 key— verifies Auto also handles comma-separated input ("65,65")